package com.lap.auth.adapter.driven.web.dict;

import com.lap.auth.application.dict.DictAppService;
import com.lap.auth.application.dict.command.BatchCreateDictCmd;
import com.lap.auth.application.dict.dto.DictDto;
import com.lap.auth.application.dict.dto.FindDictByTypeCodeQuery;
import com.lap.framework.annotation.NotAuth;
import com.lap.watchdog.starter.annotation.RepeatSubmit;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.List;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "数据字典管理", description = "提供数据字典基本操作")
@RequiredArgsConstructor
@RestController
@RequestMapping("api/v1/dictionaries")
public class DictController {

  private final DictAppService dictAppService;

  @Operation(summary = "添加字典")
  @RepeatSubmit
  @PostMapping
  public void batchCreateDict(@RequestBody @Valid BatchCreateDictCmd cmd) {
    dictAppService.batchCreateDict(cmd);
  }

  @Operation(summary = "根据类型编码获取字典")
  @GetMapping
  public List<DictDto> getDictList(String dictTypeCode) {
    return dictAppService.getDictList(dictTypeCode);
  }

  @Operation(summary = "根据类型编码集合获取字典")
  @NotAuth
  @PostMapping("dict-type-code")
  public Map<String, List<DictDto>> getDictList(@RequestBody FindDictByTypeCodeQuery query) {
    return dictAppService.queryDictList(query.getDictTypeCodes());
  }
}
